<?php
/**
 * +--------------------------------------------------------------
 * | eLuoPHP
 * +--------------------------------------------------------------
 * | Copyright (c) 2013-2019 http://qxwoo.cn All rights reserved.
 * +--------------------------------------------------------------
 * | y139w [y139w@163.com]
 * +--------------------------------------------------------------
 * | 配置处理类文件
 * +--------------------------------------------------------------
 */

namespace luo;


class Config
{

    /**
     * 配置项数组
     * @var array
     */
    private static $_configs = [];

    /**
     * 获取配置项
     * @param null $name
     * @return array|mixed|null
     */
    public static function get($name = null){

        if(empty($name)){
            // 如果为空，就返回配置
            return self::$_configs;
        }else if(is_string($name)){
            // 获取配置项
            return self::$_configs[$name];
        }
        return null;

    }

    /**
     * 设置配置项
     * @param $name
     * @param null $value
     * @return mixed
     */
    public static function set($name, $value = null){

        if(is_string($name)){
            // 如果是字符串
            self::$_configs[$name] = $value;
        }else if(is_array($name)){
            // 如果是数组
            foreach($name as $key=>$val){
                self::$_configs[$key] = $val;
            }
        }
        return self::$_configs;

    }

    /**
     * 加载配置文件
     * @param $file
     * @return mixed
     */
    public static function load($file, $configType = false){

        if(is_file($file)){
            // 获取文件扩展名
            $type = pathinfo($file, PATHINFO_EXTENSION);
            $config = '';
            // 当扩展名为php时
            if('php' == $type){
                $config = include $file;
            }
            if($configType){
                $config = [$configType => include $file];
            }
            self::set($config);
        }
        return ;

    }

}